<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adds a parameter to a stored procedure or a remote stored procedure</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-close.html">mssql_close</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mssql-bind" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_bind</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_bind</span> &mdash; <span class="dc-title">Adds a parameter to a stored procedure or a remote stored procedure</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mssql-bind-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>mssql_bind</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$param_name</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$var</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_output</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_null</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$maxlen</code><span class="initializer"> = -1</span></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   Binds a parameter to a stored procedure or a remote stored procedure.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-bind-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">stmt</code></em></dt>

     <dd>

      <p class="para">
       Statement resource, obtained with <span class="function"><a href="function.mssql-init.html" class="function">mssql_init()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">param_name</code></em></dt>

     <dd>

      <p class="para">
       The parameter name, as a string.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        You have to include the <em>@</em> character, like in the
        T-SQL syntax. See the explanation included in
        <span class="function"><a href="function.mssql-execute.html" class="function">mssql_execute()</a></span>.
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt>
<em><code class="parameter">var</code></em></dt>

     <dd>

      <p class="para">
       The PHP variable you&#039;ll bind the MSSQL parameter to. It is passed by
       reference, to retrieve OUTPUT and RETVAL values after
       the procedure execution.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">type</code></em></dt>

     <dd>

      <p class="para">
       One of: <strong><code>SQLTEXT</code></strong>,
       <strong><code>SQLVARCHAR</code></strong>, <strong><code>SQLCHAR</code></strong>,
       <strong><code>SQLINT1</code></strong>, <strong><code>SQLINT2</code></strong>,
       <strong><code>SQLINT4</code></strong>, <strong><code>SQLBIT</code></strong>,
       <strong><code>SQLFLT4</code></strong>, <strong><code>SQLFLT8</code></strong>,
       <strong><code>SQLFLTN</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">is_output</code></em></dt>

     <dd>

      <p class="para">
       Whether the value is an OUTPUT parameter or not. If it&#039;s an OUTPUT
       parameter and you don&#039;t mention it, it will be treated as a normal
       input parameter and no error will be thrown.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">is_null</code></em></dt>

     <dd>

      <p class="para">
       Whether the parameter is <strong><code>NULL</code></strong> or not. Passing the <strong><code>NULL</code></strong> value as
       <em><code class="parameter">var</code></em> will not do the job.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">maxlen</code></em></dt>

     <dd>

      <p class="para">
       Used with char/varchar values. You have to indicate the length of the
       data so if the parameter is a varchar(50), the type must be
       <strong><code>SQLVARCHAR</code></strong> and this value <em>50</em>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-bind-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-bind-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1491">
    <p><strong>Example #1 <span class="function"><strong>mssql_bind()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;MSSQL&nbsp;and&nbsp;select&nbsp;the&nbsp;database<br /></span><span style="color: #0000BB">mssql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'KALLESPC\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'php'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;new&nbsp;stored&nbsp;prodecure<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'NewUserRecord'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Bind&nbsp;the&nbsp;field&nbsp;names<br /></span><span style="color: #0000BB">mssql_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'@username'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'Kalle'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">SQLVARCHAR</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">60</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'@name'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Kalle'</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">SQLVARCHAR</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">60</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'@age'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">19</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">SQLINT1</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute<br /></span><span style="color: #0000BB">mssql_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Free&nbsp;statement<br /></span><span style="color: #0000BB">mssql_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mssql-bind-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mssql-execute.html" class="function" rel="rdfs-seeAlso">mssql_execute()</a> - Executes a stored procedure on a MS SQL server database</span></li>
    <li class="member"><span class="function"><a href="function.mssql-free-statement.html" class="function" rel="rdfs-seeAlso">mssql_free_statement()</a> - Free statement memory</span></li>
    <li class="member"><span class="function"><a href="function.mssql-init.html" class="function" rel="rdfs-seeAlso">mssql_init()</a> - Initializes a stored procedure or a remote stored procedure</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-close.html">mssql_close</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
